import { h, render } from 'vue'
import XtxConfirm from './confirm.vue'
type options = {
  text: string
  title?: string
}

export default function Confirm({  title, text }: options) {
  return new Promise((resolve, reject) => {
    function cancelCallback() {
      reject('取消')
      div.remove()
    }
    function confirmCallback() {
      resolve('确定')
      div.remove()
    }
    const div = document.createElement('div')
    div.setAttribute('class', 'xtx-confirm-container')
    document.body.appendChild(div)
    const vNode = h(XtxConfirm, { title, text, cancelCallback, confirmCallback })
    render(vNode, div)
  })
}
